package com.mmg.spzx.pay.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.mmg.spzx.model.vo.common.Result;
import com.mmg.spzx.model.vo.common.ResultCodeEnum;
import com.mmg.spzx.pay.properties.AlipayProperties;
import com.mmg.spzx.pay.service.AliPayService;
import com.mmg.spzx.pay.service.PaymentInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "支付宝支付")
@Controller
@RequestMapping("/api/order/alipay")
public class AliPayController {

    @Autowired
    private AliPayService aliPayService;

    @Operation(summary = "支付宝异步回调")
    @RequestMapping("/callback/notify")
    @ResponseBody
    public String alipayNotify(@RequestParam Map<String, String> paramMap, HttpServletRequest request) {
        return aliPayService.alipayNotify(paramMap,request);
    }

    @Operation(summary = "支付宝下单")
    @GetMapping("/submitAlipay/{orderNo}")
    @ResponseBody
    public Result<String> submitAlipay(@PathVariable(value = "orderNo") String orderNo) {
        String form = aliPayService.submitAlipay(orderNo);
        return Result.build(form, ResultCodeEnum.SUCCESS);
    }
}
